#include "Common.h"
#include <windows.h>
using namespace AutomatedSurfaceReconstruction;
//*****************************************************************
//FUNCTION: 
double AutomatedSurfaceReconstruction::getSystemFreeMemoryInMB()
{
	MEMORYSTATUSEX Statex;
	Statex.dwLength = sizeof(Statex);
	GlobalMemoryStatusEx(&Statex);
	return Statex.ullAvailPhys / 1024 / 1024;
}

//*****************************************************************
//FUNCTION: 
double AutomatedSurfaceReconstruction::getSystemTotalMemoryInMB()
{
	MEMORYSTATUSEX Statex;
	Statex.dwLength = sizeof(Statex);
	GlobalMemoryStatusEx(&Statex);
	return Statex.ullTotalPhys / 1024 / 1024;
}

//*****************************************************************
//FUNCTION: 
bool  AutomatedSurfaceReconstruction::isSubconfigValid(const hiveConfig::CHiveConfig* vConfig, std::string vConfigType)
{
	if (vConfig && _IS_STR_IDENTICAL(vConfig->getSubconfigType(), vConfigType))return true;
	return false;
}
//*****************************************************************
//FUNCTION: 
std::string  AutomatedSurfaceReconstruction::generateTime()
{
	time_t CurrentTimeStamp;
	struct tm* pCurrentTime;
	time(&CurrentTimeStamp);
	pCurrentTime = localtime(&CurrentTimeStamp);
	std::string CurrentTime = std::to_string(1900 + pCurrentTime->tm_year) + "-" + std::to_string(1 + pCurrentTime->tm_mon) + "-" + std::to_string(pCurrentTime->tm_hour) + "  " + std::to_string(pCurrentTime->tm_hour) + ":" + std::to_string(pCurrentTime->tm_min) + ":" + std::to_string(pCurrentTime->tm_sec);

	return CurrentTime;
}

bool AutomatedSurfaceReconstruction::convertPointCloudFromPCL2CGAL(const PCLPointSetType::Ptr& vPCLPointCloud, CGALPointSetType& voCGALPointCloud)
{
	voCGALPointCloud.reserve(vPCLPointCloud->size());
	for (auto Iter = vPCLPointCloud->cbegin(); Iter != vPCLPointCloud->cend(); Iter++) { voCGALPointCloud.insert(Point(Iter->x, Iter->y, Iter->z)); }
	return true;
}

bool AutomatedSurfaceReconstruction::convertPointCloudFromCGAL2PCL(const CGALPointSetType& vCGALPointCloud, PCLPointSetType::Ptr& voPCLPointCloud)
{
	voPCLPointCloud->resize(vCGALPointCloud.size());
	for (auto PointIndex:vCGALPointCloud)
	{	
		Point CGALPoint = vCGALPointCloud.point(PointIndex);
		voPCLPointCloud->points.emplace_back(PCLPointType((float)CGALPoint.x(), (float)CGALPoint.y(), (float)CGALPoint.z()));
	}
	return 0;
}